<?php

ob_start();
session_start();
date_default_timezone_set('Asia/Bangkok');
//$cn_number=$_GET['cn_number'];
$cn_id = $_GET['cn_id'];

//$c_refNumber=$_GET['c_refNumber'];

require('fpdf.php');
define('FPDF_FONTPATH', 'font/');

class PDF extends FPDF {

    function conv($string) {
        return iconv('UTF-8', 'TIS-620', $string);
    }

    function Header() {

        $this->AddFont('angsa', '', 'angsa.php');
        $this->AddFont('angsana', 'B', 'angsab.php');
        $this->SetFont('angsana', 'B', 10);
        $this->SetFont('angsana', 'B', 14);
        $this->SetLeftMargin(25);
        $this->Cell(17, 7, iconv('UTF-8', 'TIS-620', 'Ref. No. : '), 0, 0, 'R');
        $this->Cell(20, 7, iconv('UTF-8', 'TIS-620', '' . $_GET['c_refNumber']), 1, 0, 'C');
        $this->Cell(134, 7, iconv('UTF-8', 'TIS-620', 'F-IT-002  R02'), 0, 1, 'R');
        $this->Ln(2);
        $this->line(25, 41, 195, 41);
        $this->line(25, 104, 195, 104);
        $this->line(25, 137, 195, 137);
    }

}

$pdf = new PDF();
//$header=array('No.','รหัสเครื่อง','ชื่อเครื่อง','แผนก/ฝ่าย','IP No.');
//*** Load MySQL Data ***//
include "../connect.php";
$strSQL = "SELECT * FROM comname LEFT JOIN depart ON comname.de_id = depart.id
                                                         LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                         LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                         LEFT JOIN employee ON comname.emp_id = employee.emp_id   
                                                          LEFT  JOIN product_detail ON comname.cn_number =  product_detail.pd_id
                                                         WHERE comname.cn_id = '$cn_id' 
 ";

$objQuery = mysql_query($strSQL);
mysql_query("set NAMES'TIS620'");
$resultData = array();
for ($i = 0; $i < mysql_num_rows($objQuery); $i++) {
    $result = mysql_fetch_array($objQuery);
    array_push($resultData, $result);
}
//*** Load MySQL Data 2 ***//
include "../connect.php";
$strSQL2 = "SELECT pd_name FROM computer  LEFT  JOIN product_detail ON computer.c_mouse =  product_detail.pd_id
                                                         WHERE computer.cn_id = '$cn_id' 
 ";

$objQuery2 = mysql_query($strSQL2);
mysql_query("set NAMES'TIS620'");
$resultData2 = array();
for ($i = 0; $i < mysql_num_rows($objQuery2); $i++) {
    $result2 = mysql_fetch_array($objQuery2);
    array_push($resultData2, $result2);
}
//*** Load MySQL Data 3 ***//
include "../connect.php";
$strSQL3 = "SELECT pd_name FROM computer  LEFT  JOIN product_detail ON computer.c_keyboard =  product_detail.pd_id
                                                         WHERE computer.cn_id = '$cn_id' 
 ";

$objQuery3 = mysql_query($strSQL3);
mysql_query("set NAMES'TIS620'");
$resultData3 = array();
for ($i = 0; $i < mysql_num_rows($objQuery3); $i++) {
    $result3 = mysql_fetch_array($objQuery3);
    array_push($resultData3, $result3);
}

//*** Load MySQL Data 4 ***//
include "../connect.php";
$strSQL4 = "SELECT pd_name FROM computer  LEFT  JOIN product_detail ON computer.c_monitor =  product_detail.pd_id
                                                         WHERE computer.cn_id = '$cn_id' 
 ";

$objQuery4 = mysql_query($strSQL4);
mysql_query("set NAMES'TIS620'");
$resultData4 = array();
for ($i = 0; $i < mysql_num_rows($objQuery4); $i++) {
    $result4 = mysql_fetch_array($objQuery4);
    array_push($resultData4, $result4);
}

//*** Load MySQL Data 5 ***//
include "../connect.php";
$strSQL5 = "SELECT pd_name FROM comother  LEFT  JOIN product_detail ON comother.oth_detail =  product_detail.pd_id
                                                         WHERE comother.cn_id = '$cn_id' 
 ";

$objQuery5 = mysql_query($strSQL5);
mysql_query("set NAMES'TIS620'");
$resultData5 = array();
for ($i = 0; $i < mysql_num_rows($objQuery5); $i++) {
    $result5 = mysql_fetch_array($objQuery5);
    array_push($resultData5, $result5);
}
//*** Load MySQL Data 5 ***//
include "../connect.php";
$strSQLoth = "SELECT * FROM comname
                                                                LEFT JOIN depart ON comname.de_id = depart.id
                                                                LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                                LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                                LEFT JOIN employee ON comname.emp_id = employee.emp_id
                                                                LEFT JOIN product_detail ON comother.oth_detail = product_detail.pd_id
                                                                LEFT JOIN product ON product_detail.prd_id = product.prd_id
                                                                WHERE comname.cn_id ='$cn_id'
                                                                AND type_id = '6'
 ";

$objQueryoth = mysql_query($strSQLoth);
mysql_query("set NAMES'TIS620'");
$resultDataoth = array();
for ($i = 0; $i < mysql_num_rows($objQueryoth); $i++) {
    $resultoth = mysql_fetch_array($objQueryoth);
    array_push($resultDataoth, $resultoth);
}

include "../connect.php";
$strSQLoth2 = "SELECT * FROM comname
                                                                LEFT JOIN depart ON comname.de_id = depart.id
                                                                LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                                LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                                LEFT JOIN employee ON comname.emp_id = employee.emp_id
                                                                LEFT JOIN product_detail ON comother.oth_detail = product_detail.pd_id
                                                                LEFT JOIN product ON product_detail.prd_id = product.prd_id
                                                                WHERE comname.cn_id ='$cn_id'
                                                                AND type_id = '5'
 ";

$objQueryoth2 = mysql_query($strSQLoth2);
mysql_query("set NAMES'TIS620'");
$resultDataoth2 = array();
for ($i = 0; $i < mysql_num_rows($objQueryoth2); $i++) {
    $resultoth2 = mysql_fetch_array($objQueryoth2);
    array_push($resultDataoth2, $resultoth2);
}


include "../connect.php";
$strSQLoth3 = "SELECT * FROM comname
                                                                LEFT JOIN depart ON comname.de_id = depart.id
                                                                LEFT JOIN computer ON comname.cn_id = computer.cn_id
                                                                LEFT JOIN comother ON comname.cn_id = comother.cn_id
                                                                LEFT JOIN employee ON comname.emp_id = employee.emp_id
                                                                LEFT JOIN product_detail ON comother.oth_detail = product_detail.pd_id
                                                                LEFT JOIN product ON product_detail.prd_id = product.prd_id
                                                                WHERE comname.cn_id ='$cn_id'
                                                                AND type_id = '8'
 ";

$objQueryoth3 = mysql_query($strSQLoth3);
mysql_query("set NAMES'TIS620'");
$resultDataoth3 = array();
for ($i = 0; $i < mysql_num_rows($objQueryoth3); $i++) {
    $resultoth3 = mysql_fetch_array($objQueryoth3);
    array_push($resultDataoth3, $resultoth3);
}


//************************//
$pdf->AddPage('P', 'A4');
$pdf->AliasNbPages('tp');
$pdf->SetLeftMargin(25);
$pdf->SetFillColor(194, 194, 194);
$pdf->AddFont('angsai', 'BI', 'angsai.php');
$pdf->SetFont('angsai', 'BI', 16);
$pdf->SetFont('angsana', 'B', 16);
$pdf->Cell(170, 7, iconv('UTF-8', 'TIS-620', 'ใบประวัติเครื่องคอมพิวเตอร์และอุปกรณ์ต่อพ่วง'), 1, 1, 'C', true);
$pdf->Ln(2);
$pdf->SetFont('angsana', 'B', 14);
$pdf->Ln(2);
$pdf->Cell(17, 7, iconv('UTF-8', 'TIS-620', 'Com ID : '), 0, 0, 'R');
$pdf->Cell(38, 7, iconv('UTF-8', 'TIS-620', '' . $result['pd_name']), 1, 0, 'C');
$pdf->Cell(23, 7, iconv('UTF-8', 'TIS-620', 'User : '), 0, 0, 'R');
$pdf->Cell(38, 7, iconv('UTF-8', 'TIS-620', '' . $result['emp_nameEng']), 1, 1, 'C');
$pdf->Ln(4);

$pdf->SetFont('angsai', 'BI', 14);
$pdf->Cell(170, 7, iconv('UTF-8', 'TIS-620', '        Computer Set'), LR, 1, 'L');
$pdf->SetLeftMargin(25);
$pdf->SetFont('angsana', 'B', 14);
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'M/B Brand/Model : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_mb']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'VGA Brand/Model : '), 0, 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_vga']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'CPU Brand/Model : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_cpu']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'FDD Brand/Model : '), 0, 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_fdd']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'RAM Brand/Vol/Size : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_ram']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'K/B Brand/Model : '), 0, 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result3['pd_name']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'HDD Brand/Vol/Size : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_hdd']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'Mouse Brand/Model : '), 0, 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result2['pd_name']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'Sound Brand/Model : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_sound']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'Monitor Brand/Model : '), 0, 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result4['pd_name']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'CD-ROM Brand/Model : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_cdRom']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'Speaker Brand : '), 0, 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_speaker']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(37, 7, iconv('UTF-8', 'TIS-620', 'Lan Card Brand/Model : '), 'L', 0, 'L');
$pdf->Cell(43, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_lan']), 1, 0, 'C');
$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 0, 0, 'R');
$pdf->Cell(18, 7, iconv('UTF-8', 'TIS-620', 'Notice : '), 0, 0, 'L');
$pdf->Cell(62, 7, iconv('UTF-8', 'TIS-620', '' . $result['c_notic']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->SetFont('angsai', 'BI', 14);
$pdf->Cell(170, 7, iconv('UTF-8', 'TIS-620', '        Other Device'), 'LR', 1, 'L');
$pdf->SetFont('angsana', 'B', 14);
$pdf->Cell(20, 7, iconv('UTF-8', 'TIS-620', 'Device : '), 'L', 0, 'L');
$pdf->Cell(40, 7, iconv('UTF-8', 'TIS-620', '' . $resultoth['oth_name']), 1, 0, 'C');
$pdf->Cell(20, 7, iconv('UTF-8', 'TIS-620', 'Details: '), 0, 0, 'C');
$pdf->Cell(85, 7, iconv('UTF-8', 'TIS-620', '' . $resultoth['pd_name']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(20, 7, iconv('UTF-8', 'TIS-620', 'Device : '), 'L', 0, 'L');
$pdf->Cell(40, 7, iconv('UTF-8', 'TIS-620', '' . $resultoth2['oth_name']), 1, 0, 'C');
$pdf->Cell(20, 7, iconv('UTF-8', 'TIS-620', 'Details: '), 0, 0, 'C');
$pdf->Cell(85, 7, iconv('UTF-8', 'TIS-620', '' . $resultoth2['pd_name']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');

$pdf->Cell(20, 7, iconv('UTF-8', 'TIS-620', 'Device : '), 'L', 0, 'L');
$pdf->Cell(40, 7, iconv('UTF-8', 'TIS-620', '' . $resultoth3['oth_name']), 1, 0, 'C');
$pdf->Cell(20, 7, iconv('UTF-8', 'TIS-620', 'Details: '), 0, 0, 'C');
$pdf->Cell(85, 7, iconv('UTF-8', 'TIS-620', '' . $resultoth3['pd_name']), 1, 0, 'C');

$pdf->Cell(5, 7, iconv('UTF-8', 'TIS-620', ''), 'R', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');
$pdf->Cell(170, 1, iconv('UTF-8', 'TIS-620', ''), 'LR', 1, 'C');
$pdf->Output();
?>